package com.muzi.weshop.common.base;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.muzi.weshop.R2;
import com.muzi.weshop.common.http.presenter.IBasePresenter;
import com.muzi.weshop.common.presenter.ApiPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.rubintry.speak.OkSpeaker;

/**
 * @@author 郑天阳
 */
public abstract class BaseActivity extends RxBaseActivity implements IBasePresenter {

    
    public ApiPresenter apiPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //防止软键盘弹出的时候遮盖EditText
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        //渲染界面
        setContentView(attachedLayout());
        //ButterKnife的绑定，绑定控件以及点击事件之类的，节省代码
        //https://github.com/JakeWharton/butterknife
        ButterKnife.bind(this);

        //是否隐藏状态栏（就是显示电量的那个地方）
        if(hideStatusBar()){
            //隐藏标题
            BarUtils.transparentStatusBar(this);
        }else{
            BarUtils.setStatusBarColor(this , Color.WHITE);
        }
        //LightMode白底黑字,状态栏的主题
        BarUtils.setStatusBarLightMode(this , true);

        //这是一个用来请求网络数据的类,MVP里面的P(Presenter)
        apiPresenter = new ApiPresenter(this , this);

        initViews();
        requestData();
    }

    /**
     * 是否显示状态栏
     * 如果不显示则自动调整为沉浸式状态栏
     * @return
     */
    protected abstract boolean hideStatusBar();

    /**
     * 绑定activity的布局文件
     * @return
     */
    protected abstract int attachedLayout();


    /**
     * 初始化view
     */
    protected abstract void initViews();

    /**
     * 请求网络数据
     */
    protected abstract void requestData();






    @Override
    public void onNext(Object o, int requestCode) {
        
    }

    @Override
    public void onError(Throwable e, int request) {

    }

    @Override
    protected void onStop() {
        OkSpeaker.get().release();
        super.onStop();
    }
}
